import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';

@Component({
  selector: 'app-tab2',
  templateUrl: 'tab2.page.html',
  styleUrls: ['tab2.page.scss']
})
export class Tab2Page {
  url = 'http://101.96,128.94:9999/data/product/list.php?pno=';
  res: Result;
  constructor(private http: HttpClient) { }
  ngOnInit(): void {
    this.http.get(this.url + 1).subscribe(
      (res: Result) => {

      }
    )
  }
  // 下拉刷新
  doRefresh(e) {
    this.http.get(this.url + 1).subscribe(
      (res: Result) => {
        this.res = res;
        e.target.complete();
        // 停止此次刷新
      }
    )
  }
  // 加载更多
  loadData(e) {
    let nextPage = this.res.pno + 1;
    this.http.get(this.url + nextPage).subscribe(
      (res: Result) => {
        res.data = this.res.data.concat(res.data);
        e.target.complete();
        // 此次加载结束，去加载下一次
      }
    )
  }
}
// 详情页面  ionic g page detail
interface Result {
  data: ResultData[];
  pageCount: number;
  pageSize: number;
  pno: number;
  recordCount: number;
}
interface ResultData {
  is_onsale: string;
  lid: string;
  pic: string;
  price: string;
  sold_count: string;
  title: string;
}